package com.com.demo2;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class TCPClient2 {
    public static void main(String[] args) throws IOException, IOException {
        Scanner scanner = new Scanner(System.in);
        String ip = "192.168.137.1";
        int port = 8088;
        while (true) {
            Socket socket = new Socket(ip, port);
            System.out.print("请输入:");
            String msg = scanner.next();
// 写给服务器
            DataOutputStream dos = new
                    DataOutputStream(socket.getOutputStream());
            dos.writeUTF(msg);
// 退出机制
            if ("quit".equalsIgnoreCase(msg)) {
                break;
            }
//获取客户端的信息
            DataInputStream dis = new DataInputStream(socket.getInputStream());
            String data = dis.readUTF();
            System.out.println("客户端接收服务器的响应：" + data);
            dis.close();

            dos.close();
        }

    }
}
